package cn.cy.controller;

import cn.cy.domain.DAO.Semester2step;
import cn.cy.domain.Const.LowerConst;
import cn.cy.domain.Point;
import cn.cy.domain.StepResult;
import cn.cy.domain.Student;
import cn.cy.service.LowerComputer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: Xucranger
 * @Date: 22/5/1 17:15
 */

@Controller
@RequestMapping("/step")
public class StepController {
    private static final Integer drawerstep = LowerConst.drawerstep;

    @Autowired
    Semester2step semester2Step;
    @Autowired
    LowerComputer lowerComputer;

//    @RequestMapping("/popdrawer")
//    public String pushdrawer(){
//         String result = "";
//         result = lowerComputer.movedrawer(drawerstep);
//         System.out.println(result);
//         return result;
//    }

    @RequestMapping("/moveto")
    @ResponseBody
    public String moveto(@RequestBody Student student){
        Point point = semester2Step.getByKey(student.getSemester());
        StepResult moveto = lowerComputer.arriveto(point.getX(),point.getY());
        //推出
        StepResult pushdrawer = lowerComputer.movedrawer(drawerstep);
        if(moveto.equals("success")&&pushdrawer.equals("success")){
            return "success!";
        }
        return "fail!";
    }
}
